﻿namespace JunFan.Tests.UnitTests
{
    using System;
    using Domain;
    using FluentAssertions;
    using Infrastructure;
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    [TestClass]
    public class CalculatingCycleTime
    {
        /// <summary>
        /// Given: a completed item
        /// When: Calculate cycle time
        /// Then: Cycle time should be Complete date - Start date
        /// </summary>
        [TestMethod]
        public void OnCompletedItemsShouldBeCompleteDateMinusStartDate()
        {
            var startDate = new DateTime(2012, 5, 20);

            const int ExpectedCycleTime = 11;
            var completeDate = startDate.AddDays(ExpectedCycleTime);

            Item completedItem = Given.CompletedItem.StartedOn(startDate).CompletedOn(completeDate).Build();

            completedItem.CycleTime.Should().Be(ExpectedCycleTime);
        }

        /// <summary>
        /// Given: a started item
        /// When: Calculate cycle time
        /// Then: Cycle time should be Today - Start date
        /// </summary>
        [TestMethod]
        public void OnInProgressItemsShouldBeTodayMinusStartDate()
        {
            const int ExpectedCycleTime = 7;
            DateTime startDate = DateTime.Today.AddDays(-ExpectedCycleTime);

            var startedItem = Given.StartedItem.StartedOn(startDate).Build();

            startedItem.CycleTime.Should().Be(ExpectedCycleTime);
        }

        /// <summary>
        /// Given: a non started item
        /// When: Calculate cycle time
        /// Then: Cycle time should be Zero
        /// </summary>
        [TestMethod]
        public void OnBacklogItemsShouldBeZero()
        {
            var backlogItem = Given.NewItem.Build();

            backlogItem.CycleTime.Should().Be(0);
        }
    }
}